home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Grafik / BMP2SPEC / Source / BMP2SPEC.orig.C < prev   
C/C++ Source or Header  |  1998-06-21  |  5KB  |  213 lines

  1. /* BMP2SPEC version 1.0 */
  2. /* By the infamous BLOOD! */
  3. /* (C)1996 Cheese Freak Software */
  4. /* This prog is most definitely FREEWARE! */
  5. /* But please don't distribute updated versions without asking first...! */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include "bmp2spec.h"
  10.  
  11. void main(int argc, char *argv[])
  12. {
  13.     FILE *fp1, *fp2;
  14.     BYTE header[24],checkbit=255,data[6144], screen[6144];
  15.     int count,count2,ptr,ptr2,ptr3,x,y,z,result;
  16.  
  17.     getheader(header);
  18.  
  19.     printf("\n\nBMP2SPEC version 1.0\n");
  20.     printf("Written by the infamous BLOOD!\naka l.d.tonks@bra0202.wins.icl.co.uk\n");
  21.     printf("(C)1996 Cheese Freak Software\n\n");
  22.     printf("This program is FREEWARE! Don't pay more than 2p for it!\n\n");
  23.     
  24.     if(argc!=3)
  25.     {
  26.         printf("Usage : BMP2SPEC <bitmap file input> <tape file output>\n");
  27.         printf("Example : BMP2SPEC jetset.bmp jetset.tap\n\n");
  28.         exit(0);
  29.     }
  30.     else
  31.     {
  32.         printf("Converting %s to %s....\n",argv[1],argv[2]);
  33.         fp1=fopen(argv[1],"rb");
  34.         if(fp1==NULL)
  35.         {
  36.             printf("Error opening %s...!\n",argv[1]);
  37.             exit(1);
  38.         };
  39.         fp2=fopen(argv[2],"wb");
  40.         if(fp2==NULL)
  41.         {
  42.             printf("Error opening %s...!\n",argv[2]);
  43.             exit(1);
  44.         };
  45.  
  46.         result=fwrite(header,24,1,fp2);
  47.         if(result!=1)
  48.         {
  49.             printf("Can't write to %s...!\n",argv[2]);
  50.             exit(1);
  51.         };
  52.         
  53.         result=fread(data,62,1,fp1);
  54.         if(result!=1)
  55.         {
  56.             printf("Can't read from %s...!\n",argv[1]);
  57.             exit(1);
  58.         };
  59.  
  60.         printf("Reading bitmap data...\n");
  61.         result=fread(screen,6144,1,fp1);
  62.         if(result!=1)
  63.         {
  64.             printf("Read error in %s...!\n",argv[1]);
  65.             exit(1);
  66.         };
  67.         
  68.         printf("Sorting bitmap data...\n");
  69.         ptr=0;
  70.         ptr2=6144;
  71.         ptr3=0;
  72.         for(count=0;count<192;count++)
  73.         {
  74.             ptr2=ptr2-32;
  75.             ptr3=ptr2;
  76.             for(count2=0;count2<32;count2++)
  77.             {
  78.                 data[ptr]=screen[ptr3];
  79.                 ptr++;
  80.                 ptr3++;
  81.             };
  82.         };
  83.  
  84.         printf("Creating Spectrum Screen...\n");        
  85.         x=0;
  86.         y=0;
  87.         z=0;
  88.         
  89.         for(count=0;count<2048;count++)
  90.         {
  91.             screen[count]=data[x+(y*32)];
  92.             screen[count]=screen[count]^255;
  93.             checkbit = (checkbit ^ screen[count]);
  94.             x++;
  95.             if(x>=32)
  96.             {
  97.                 x=0;
  98.                 y=y+8;
  99.                 if(y>=64)
  100.                 {
  101.                     z++;
  102.                     y=z;
  103.                 };
  104.             };
  105.         };
  106.  
  107.         x=0;
  108.         y=64;
  109.         z=64;
  110.         
  111.         for(count=2048;count<4096;count++)
  112.         {
  113.             screen[count]=data[x+(y*32)];
  114.             screen[count]=screen[count]^255;
  115.             checkbit = (checkbit ^ screen[count]);
  116.             x++;
  117.             if(x>=32)
  118.             {
  119.                 x=0;
  120.                 y=y+8;
  121.                 if(y>=128)
  122.                 {
  123.                     z++;
  124.                     y=z;
  125.                 };
  126.             };
  127.         };
  128.  
  129.         x=0;
  130.         y=128;
  131.         z=128;
  132.         
  133.         for(count=4096;count<6144;count++)
  134.         {
  135.             screen[count]=data[x+(y*32)];
  136.             screen[count]=screen[count]^255;
  137.             checkbit = (checkbit ^ screen[count]);
  138.             x++;
  139.             if(x>=32)
  140.             {
  141.                 x=0;
  142.                 y=y+8;
  143.                 if(y>=192)
  144.                 {
  145.                     z++;
  146.                     y=z;
  147.                 };
  148.             };
  149.         };
  150.  
  151.         printf("Writing TAP file...\n");
  152.         result=fwrite(screen,6144,1,fp2);
  153.         if(result!=1)
  154.         {
  155.             printf("Error writing to %s...!\n",argv[2]);
  156.             exit(1);
  157.         };
  158.  
  159.         data[0]=56;
  160.         for(count=0;count<768;count++)
  161.         {
  162.             result=fwrite(data,1,1,fp2);
  163.             if(result!=1)
  164.             {
  165.                 printf("Error writing to %s...!\n",argv[2]);
  166.                 exit(1);
  167.             };
  168.  
  169.         };
  170.         
  171.         result=fwrite(&checkbit,1,1,fp2);
  172.         if(result!=1)
  173.         {
  174.             printf("Error writing to %s...!\n",argv[2]);
  175.             exit(1);
  176.         };
  177.         
  178.         printf("\nConversion done...!\n");
  179.  
  180.         fclose(fp1);
  181.         fclose(fp2);
  182.     };
  183. }
  184.  
  185.  
  186. void getheader(BYTE header[24])
  187. {
  188.     header[0]=19;    
  189.     header[1]=0;    
  190.     header[2]=0;    
  191.     header[3]=3;    
  192.     header[4]=115;    
  193.     header[5]=99;    
  194.     header[6]=114;    
  195.     header[7]=101;    
  196.     header[8]=101;    
  197.     header[9]=110;    
  198.     header[10]=32;    
  199.     header[11]=32;    
  200.     header[12]=32;    
  201.     header[13]=32;    
  202.     header[14]=0;    
  203.     header[15]=27;    
  204.     header[16]=0;    
  205.     header[17]=64;    
  206.     header[18]=0;    
  207.     header[19]=128;    
  208.     header[20]=212;    
  209.     header[21]=2;    
  210.     header[22]=27;    
  211.     header[23]=255;    
  212. }
  213.